<?php


namespace app\game;


use app\game\node\NodeFood;

class Scenes
{
    /**
     * @var Form
     */
    protected $form;

    /**
     * @var RandRowCol
     */
    protected $randRowCol;

    /**
     * @var FoodList
     */
    protected $foodList;

    /**
     * @var Snake
     */
    protected $snake;

    public function __construct(Form $form, RandRowCol $randRowCol, Snake $snake, FoodList $foodList)
    {
        $this->form = $form;
        $this->randRowCol = $randRowCol;
        $this->snake = $snake;
        $this->foodList = $foodList;

        $form->setHeight(10);
        $form->setWidth(30);
        $form->init();

        $randRowCol->setForm($this->form);
        $snake->setForm($form);
        $snake->setFoodList($foodList);
    }

    public function run()
    {
        try {
            while (true)
            {
                $this->form->show();

                $this->foodList->createFood($this->randRowCol, $this->form);

                $this->snake->move();

                usleep(500000);
            }
        }catch (\Exception $exception){
            echo $exception->getMessage();
        }
    }
}